﻿// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="Problem4.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation.  All rights reserved. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// </copyright>
// <summary>
//   Defines the Problem4 type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
namespace EulerProblemsCSharp.Problems
{
    using System.Linq;

    /// <summary>
    /// Problem 4.
    /// </summary>
    public class Problem4 : ProblemBase
    {
        /// <summary>
        /// Gets Number.
        /// </summary>
        /// <value>
        /// The number.
        /// </value>
        public override int Number
        {
            get
            {
                return 4;
            }
        }

        /// <summary>
        /// Gets Description.
        /// </summary>
        /// <value>
        /// The description.
        /// </value>
        public override string Description
        {
            get
            {
                return "Find the largest palindrome made from the product of two 3-digit numbers.";
            }
        }

        /// <summary>
        /// Solves problem 4.
        /// </summary>
        /// <returns>
        /// The solution.
        /// </returns>
        public override object Solve()
        {            
            var query = from a in Enumerable.Range(900, 99)
                        from b in Enumerable.Range(900, 99)
                        select a * b
                        into product 
                                where product.IsPalindrome() 
                                select product;

            var answer = query.Max();

            return answer;
        }
    }
}